/*
 * Copyright (C) 2008-2012  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _erat_h
#define _erat_h

#include "etypes.h"

#define rat_num(rat)		(rat).num
#define rat_den(rat)		(rat).den
#define rat_get_d(rat)							\
    ((efloat_t)rat_num(rat) / (efloat_t)rat_den(rat))

#define erat_num(rat)		(rat)->num
#define erat_den(rat)		(rat)->den
#define erat_get_d(rat)							\
    ((efloat_t)erat_num(rat) / (efloat_t)erat_den(rat))

/*
 * Types
 */
struct rat {
    eword_t		num;
    eword_t		den;
};

/*
 * Prototypes
 */
extern ebool_t
erat_set_si(erat_t u, eword_t n, eword_t d);

extern int
erat_cmp(erat_t u, erat_t v);

extern ebool_t
erat_add(erat_t u, erat_t v, erat_t w);

extern ebool_t
erat_sub(erat_t u, erat_t v, erat_t w);

extern ebool_t
erat_mul(erat_t u, erat_t v, erat_t w);

extern ebool_t
erat_div(erat_t u, erat_t v, erat_t w);

extern ebool_t
erat_canonicalize(erat_t rat);

#endif /* _erat_h */
